<?php
include 'auth.interface.php';

class auth implements auth_int 
{
	private $auth_link;

	public function __construct()
	{
		$this->auth_link  = mysql_connect(config::getconfig("_auth_db_host"), config::getconfig("_auth_db_user"), config::getconfig("_auth_db_password"), true);
		mysql_select_db(config::getconfig("_auth_db_table_name"),$this->auth_link);
	}
	
	public function isOnline()
	{
		
		$res = mysql_query("SELECT username, password, salt FROM ".config::getconfig("_auth_db_table_prefix")."user WHERE username = '".$_SESSION['username']."'",$this->auth_link);
		echo mysql_error($this->auth_link);
		list($username,$userpassword, $salt) = mysql_fetch_row($res);
		if(md5($username.$userpassword.$salt) == $_SESSION['hash'])
		{
			return true;
		}
		else{return false;}
		mysql_close($this->auth_link);
		FB::info("QUery");
	}
	
	public function isAuthenticate()
	{
		$res = mysql_query("SELECT username, password, salt FROM ".config::getconfig("_auth_db_table_prefix")."user WHERE username = '".$_POST['user']."'",$this->auth_link);
		echo mysql_error($this->auth_link);
		list($username,$userpassword, $salt) = mysql_fetch_row($res);
		if(MD5(MD5($_POST['password']).$salt) == $userpassword){return array("username"=>$username,"hash"=>md5($username.$userpassword.$salt));}
		else{return false;}
		mysql_close($this->auth_link);
	}
}
?>